from pyspark import SparkContext, SparkConf

conf = SparkConf().setAppName("SortBy").setMaster("local")
sc = SparkContext(conf=conf)

rdd = sc.parallelize([("apple", 10), ("banana", 5), ("orange", 20), ("pear", 15)])

sorted_rdd = rdd.sortBy(lambda x: x[1], ascending=False, numPartitions=1)

print(sorted_rdd.collect())
sc.stop()